home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Interactive Web Graphics with Shout 3D
/
Interactive Web Graphics With Shout 3D.iso
/
pc
/
Shout3Ddemo
/
Shout3d_runtime
/
codebase
/
custom_nodes
/
ScreenBoxPickerEffect.java
< prev
next >
Wrap
Text File
|
2000-11-10
|
2KB
|
98 lines
/**
Company: Eyematic Interfaces
Project: Shout3D Core
Class: ScreenBoxPickerEffect
Date: November 9, 2000
Description: Picks the object under the cursor and draws a screenspace box around it.
(C) Copyright Eyematic Interfaces, Inc. - 1997/1998/1999/2000 - All rights reserved
*/
package custom_nodes;
import shout3d.core.*;
import shout3d.*;
import shout3d.core.awt.*;
import java.awt.*;
import java.awt.image.*;
/**
* ScreenBoxPickerEffect
*
* @author Paul Isaacs
* @author Jim Stewartson
* @author Hugues Labbe
*
*/
public class ScreenBoxPickerEffect extends PostRenderEffect implements DeviceObserver
{
Picker picker;
int x;
int y;
boolean mouseIsInPanel = false;
/**
* Constructs a default DEFNamePickerEffect node.
*/
public ScreenBoxPickerEffect()
{
super();
}
/**
* When the viewer is set, register with it to receive DeviceInput.
*/
public void setViewer(Shout3DViewer v){
// Unregister with old viewer
if (getViewer() != null)
getViewer().getDeviceListener().removeDeviceObserver(this, "MouseInput");
// Change viewers.
super.setViewer(v);
// Register with new viewer
if (getViewer() != null){
getViewer().getDeviceListener().addDeviceObserver(this, "MouseInput", null);
picker = getViewer().getNewPicker();
}
}
public boolean onDeviceInput(DeviceInput di, Object userData)
{
if ( !(di instanceof MouseInput))
return false;
MouseInput mi = (MouseInput)di;
switch (mi.which) {
case MouseInput.DOWN:
case MouseInput.DRAG:
case MouseInput.MOVE:
x = mi.x;
y = mi.y;
mouseIsInPanel = true;
break;
case MouseInput.ENTER:
mouseIsInPanel = true;
break;
case MouseInput.EXIT:
mouseIsInPanel = false;
break;
default:
break;
}
return false;
}
public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight)
{
if (mouseIsInPanel) {
Node[] node = picker.pickClosest(x, y);
if (node == null)
return;
// Get the screen space bounds of the selection:
float[] bounds = { 0, 0, 0, 0 };
if (picker.getProjectedBounds(node,false, bounds)){
g.drawRect((int)bounds[0], (int)bounds[1], (int)(bounds[2]-bounds[0]+1), (int)(bounds[3]-bounds[1]+1));
}
}
}
}